package com.yyj.Test;

import com.yyj.pojo.Message;
import com.yyj.repository.MsgdataRepository;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

//import com.yyj.repository.MsgdataRepository;

public class Test {
    public void add(String username,String sendMsg) {
//加载mybatis文件，读入config.xml
        InputStream inputStream = Test.class.getClassLoader().getResourceAsStream("config.xml");
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        MsgdataRepository msgdataRepository = sqlSession.getMapper(MsgdataRepository.class);
        Message message = new Message();
//        int save = msgdataRepository.save(new Message("zhangsan", "hello"));
        message.setToName(username);
        message.setMessage(sendMsg);
        int save = msgdataRepository.save(message);
        System.out.println(save);

//        person.setId(2);
//        person.setName("wangwu");
//        person.setMoney(1000);
//        int row = personRepository.save(person);
//        Person byId = personRepository.findById(1);
//        int updatep= personRepository.update(new Person(1, "zhangliu", 2000));
//        System.out.println(updatep);
        sqlSession.commit();
        sqlSession.close();
    }
}
